import { Socket } from "./Socket";

// TODO:SocketManager 应该是能索引的
class SocketManager {
    private _webSockets: Map<string, Socket> = new Map<string, Socket>();

    public get(id: string) {
        if (this.has(id)) {
            return this._webSockets.get(id);
        }

        return null;
    }

    public set(id: string, socket: Socket) {
        this._webSockets.set(id, socket);
    }

    public remove(id: string) {
        if (!this.has(id)) {
            return null;
        }

        this._webSockets.delete(id);
    }

    public has(id: string) {
        return this._webSockets.has(id);
    }

    public clear() {
        this._webSockets.clear();
    }
}

const socketManager = new SocketManager();
export { socketManager, SocketManager };